﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PRJ_LDW_Eutoliso.Public
{
    public partial class Contacts : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DisplayMessage.Visible = false;
        }

        protected void btnLimpar_Click(object sender, EventArgs e)
        {
            txtAssunto.Text = "Insira o assunto";
            txtEmail.Text = "Insira seu email";
            txtMensagem.Text = "Insira sua mensagem";
            txtName.Text = "Insira seu nome";
            txtTelephone.Text = "Insira seu telefone";
        }

        protected void btnEnviar_Click(object sender, EventArgs e)
        {
            try
            {
                //here on button click what will done 
                SendMail();
                DisplayMessage.Text = "Mensagem Enviada com sucesso!";
                DisplayMessage.Visible = true;
               
                txtEmail.Text = "Insira seu email";
                txtMensagem.Text = "Insira sua mensagem";
                txtName.Text = "Insira seu nome";
                txtTelephone.Text = "Insira seu telefone";
                txtAssunto.Text = "Insira o assunto";
            }
            catch (Exception) { }

        }

        protected void SendMail()
        {
            // Gmail Address from where you send the mail
            var fromAddress = "marlinhodoors@gmail.com";
            // any address where the email will be sending
            var toAddress = txtEmail.Text.ToString() + "; marlinhodoors@hotmail.com";
            //Password of your gmail address
            const string fromPassword = "estrelinha";
            // Passing the values and make a email formate to display
            string subject = txtAssunto.Text.ToString();
            string body = "De: " + txtName.Text + "\n" + "\n";
            body += "Email: " + txtEmail.Text + "\n" + "\n";
            body += "Assunto: " + txtAssunto.Text + "\n" + "\n";
            body += "Mensagem: \n\n" + txtMensagem.Text + "\n";
            // smtp settings
            var smtp = new System.Net.Mail.SmtpClient();
            {
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.EnableSsl = true;
                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
                smtp.Timeout = 20000;
            }
            // Passing values to smtp object
            smtp.Send(fromAddress, toAddress, subject, body);

       
        }



    }
}